/*
* $Id: SectionItem.cpp 157 2010-09-29 19:15:28Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "SectionItem.h"
#include "Controls/ButtonDraw.h"

#define SIZE_BUTTON_MORE	100

CSectionItem::CSectionItem(const std::tstring& strName, IDrawer* pDrawer, int nId)
: CEditorItem(strName, nId), m_pDrawer(pDrawer), m_pButton(NULL){
	m_pFont = CCommonFunction::GetFont(_T("Book Antiqua"), m_sizefont, true, true, true);
}
CSectionItem::~CSectionItem(){
	m_pFont->DeleteObject();
	delete m_pFont;
	if(m_pButton)
		delete m_pButton;
}

void CSectionItem::Paint(CDC* dc){
	HGDIOBJ oldObj = dc->SelectObject(m_pFont->m_hObject);
	dc->SetBkMode(TRANSPARENT);
	COLORREF colorText = dc->GetTextColor();
	dc->SetTextColor(RGB(0, 0, 0));
	dc->DrawText(m_strName.c_str(), CRect(m_point, m_size), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	dc->SetTextColor(colorText);
	dc->SelectObject(oldObj);
	if(m_pButton)
		m_pButton->Paint(dc);
}
void CSectionItem::Resize(){
	std::vector<std::tstring> aString = CStringFunction::GetStringArray(m_strName, _T("\n"));
	m_size.cy = (int)aString.size() * m_sizefont + 15;
	if(m_pButton)
		m_pButton->SetCy(m_size.cy);
}

void CSectionItem::AddButton(const std::tstring& strName){
	if(m_pButton)
		delete m_pButton;
	m_pButton = new CButtonDraw(strName, m_pDrawer, m_nId);
	m_pButton->SetCx(SIZE_BUTTON_MORE);
}

bool CSectionItem::ProcessMouse(unsigned int nButton, CPoint pos, int param){
	if(m_pButton)
		return m_pButton->ProcessMouse(nButton, pos, param);
	return false;
}

bool CSectionItem::WillActive(){
	if(m_pButton)
		return true;
	return false;
}

bool CSectionItem::ProcessKey(unsigned int nChar, byte stateSysKey){
	if(m_pButton)
		return m_pButton->ProcessKey(nChar, stateSysKey);
	return false;
}

void CSectionItem::Activate(bool bActive){
	if(m_pButton)
		m_pButton->SetActive(bActive);
}

void CSectionItem::SetPosY(int nPosY){
	__super::SetPosY(nPosY);
	if(m_pButton)
		m_pButton->SetPos(CPoint(m_point.x + m_size.cx - SIZE_BUTTON_MORE, m_point.y));
}
